/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.targeter.rulesengine.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.targeter.rulesengine.model.models;
import com.targeter.rulesengine.model.modelsModel;

import java.io.Serializable;

import java.sql.Types;

import java.util.HashMap;
import java.util.Map;

/**
 * The base model implementation for the models service. Represents a row in the &quot;rulesEngine_models&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.targeter.rulesengine.model.modelsModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link modelsImpl}.
 * </p>
 *
 * @author jsalaice
 * @see modelsImpl
 * @see com.targeter.rulesengine.model.models
 * @see com.targeter.rulesengine.model.modelsModel
 * @generated
 */
public class modelsModelImpl extends BaseModelImpl<models>
	implements modelsModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a models model instance should use the {@link com.targeter.rulesengine.model.models} interface instead.
	 */
	public static final String TABLE_NAME = "rulesEngine_models";
	public static final Object[][] TABLE_COLUMNS = {
			{ "_id", Types.BIGINT },
			{ "model", Types.VARCHAR },
			{ "active_", Types.BOOLEAN }
		};
	public static final String TABLE_SQL_CREATE = "create table rulesEngine_models (_id LONG not null primary key,model VARCHAR(75) null,active_ BOOLEAN)";
	public static final String TABLE_SQL_DROP = "drop table rulesEngine_models";
	public static final String ORDER_BY_JPQL = " ORDER BY models._id ASC";
	public static final String ORDER_BY_SQL = " ORDER BY rulesEngine_models._id ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.targeter.rulesengine.model.models"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.targeter.rulesengine.model.models"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.targeter.rulesengine.model.models"),
			true);
	public static long MODEL_COLUMN_BITMASK = 1L;
	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.targeter.rulesengine.model.models"));

	public modelsModelImpl() {
	}

	public long getPrimaryKey() {
		return __id;
	}

	public void setPrimaryKey(long primaryKey) {
		set_id(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(__id);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return models.class;
	}

	public String getModelClassName() {
		return models.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("_id", get_id());
		attributes.put("model", getModel());
		attributes.put("active", getActive());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long _id = (Long)attributes.get("_id");

		if (_id != null) {
			set_id(_id);
		}

		String model = (String)attributes.get("model");

		if (model != null) {
			setModel(model);
		}

		Boolean active = (Boolean)attributes.get("active");

		if (active != null) {
			setActive(active);
		}
	}

	public long get_id() {
		return __id;
	}

	public void set_id(long _id) {
		_columnBitmask = -1L;

		__id = _id;
	}

	public String getModel() {
		if (_model == null) {
			return StringPool.BLANK;
		}
		else {
			return _model;
		}
	}

	public void setModel(String model) {
		_columnBitmask |= MODEL_COLUMN_BITMASK;

		if (_originalModel == null) {
			_originalModel = _model;
		}

		_model = model;
	}

	public String getOriginalModel() {
		return GetterUtil.getString(_originalModel);
	}

	public boolean getActive() {
		return _active;
	}

	public boolean isActive() {
		return _active;
	}

	public void setActive(boolean active) {
		_active = active;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			models.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public models toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (models)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		modelsImpl modelsImpl = new modelsImpl();

		modelsImpl.set_id(get_id());
		modelsImpl.setModel(getModel());
		modelsImpl.setActive(getActive());

		modelsImpl.resetOriginalValues();

		return modelsImpl;
	}

	public int compareTo(models models) {
		int value = 0;

		if (get_id() < models.get_id()) {
			value = -1;
		}
		else if (get_id() > models.get_id()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		models models = null;

		try {
			models = (models)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = models.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		modelsModelImpl modelsModelImpl = this;

		modelsModelImpl._originalModel = modelsModelImpl._model;

		modelsModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<models> toCacheModel() {
		modelsCacheModel modelsCacheModel = new modelsCacheModel();

		modelsCacheModel._id = get_id();

		modelsCacheModel.model = getModel();

		String model = modelsCacheModel.model;

		if ((model != null) && (model.length() == 0)) {
			modelsCacheModel.model = null;
		}

		modelsCacheModel.active = getActive();

		return modelsCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{_id=");
		sb.append(get_id());
		sb.append(", model=");
		sb.append(getModel());
		sb.append(", active=");
		sb.append(getActive());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append("com.targeter.rulesengine.model.models");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>_id</column-name><column-value><![CDATA[");
		sb.append(get_id());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>model</column-name><column-value><![CDATA[");
		sb.append(getModel());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>active</column-name><column-value><![CDATA[");
		sb.append(getActive());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = models.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			models.class
		};
	private long __id;
	private String _model;
	private String _originalModel;
	private boolean _active;
	private long _columnBitmask;
	private models _escapedModelProxy;
}